package Adapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.example.quanlithuchi.R;

import InterFaceIModel.IThuchiModel;
import ViewHoder.Thuchihoder;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ThuchiAdapter extends ArrayAdapter<IThuchiModel> {

	Context context;
	int layout;
	List<IThuchiModel>list;
	Thuchihoder hoder;
	public ThuchiAdapter(Context context, int textViewResourceId,
			List<IThuchiModel> objects) {
		super(context, textViewResourceId, objects);
		this.context=context;
		layout=textViewResourceId;
		list=objects;
		// TODO Auto-generated constructor stub
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView==null) {
			
			LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView=inflater.inflate(layout, parent, false);
			
			hoder=new Thuchihoder();
			hoder.txtLoaiThuchi=(TextView) convertView.findViewById(R.id.txtLoaithuchilist_thuchi_item);
			hoder.txtNgayThuChi=(TextView) convertView.findViewById(R.id.txtNgaythuchi_thuchi_item);
			hoder.txtSotien=(TextView) convertView.findViewById(R.id.txtSotient_thuchi_item);
			convertView.setTag(hoder);
			
		} else {
         hoder=(Thuchihoder) convertView.getTag();
		}
		IThuchiModel model=list.get(position);
		hoder.txtLoaiThuchi.setText(model.getLoaiThuChi().getTenLoai());
		hoder.txtLoaiThuchi.setTag(model);
		hoder.txtSotien.setText(String.valueOf(model.getSotien()));
		
		Date date=new Date(model.getNgaychi());
		SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
		String ngaynoString = formatter.format(date);
		hoder.txtNgayThuChi.setText(ngaynoString);
		convertView.setPadding(10, 10, 10, 10);
		return convertView;
	}
    
} 
